<template>
	<view>
		<view style="height:10px;width:100%"></view>
		<view class="uni-list">
			<view class="uni-list-cell">
				<view class="uni-list-cell-left">
					钱包地址：
				</view>
				<view class="uni-list-cell-db">
					<input type="text" @input="inputaddress" class="flex" value="" placeholder="请输入您要提币的钱包地址"/>
				</view>
			</view>
		</view>
		<view class="uni-list">
			<view class="uni-list-cell">
				<view class="uni-list-cell-left">
					币种：
				</view>
				<view class="uni-list-cell-db">
					<picker @change="bindPickerChange" :value="index" :range="array">
						<view class="uni-input" v-cloak> v-cloakarray[index]}}</view>
					</picker>
				</view>
			</view>
		</view>
		<view class="uni-list">
			<view class="uni-list-cell">
				<view class="uni-list-cell-left">
					数量：
				</view>
				<view class="uni-list-cell-db">
					<input type="number" @input="inputnumber" class="flex" value="" placeholder="请输入您要提币的数量"/>
				</view>
			</view>
		</view>
		<view class="uni-list">
			<view class="uni-list-cell">
				<view class="uni-list-cell-left">
					支付密码：
				</view>
				<view class="uni-list-cell-db">
			<input type="text" class="flex" @input="inputpaypwd" value="" placeholder="请输入您的支付密码"/>
				</view>
			</view>
		</view>
		<view style="padding: 16upx;">
		<button type="primary" style="background: #04be02;color: #fff;border: 1px solid #04ab02;" @click="submit">提交</button>
		</view>
		<view class="tip" style="padding: 16upx;">
			<view v-for="(item,index) in res" :key="index" style="color: #999;" v-cloak>{{item.coinname}}提币手续费：{{item.withdrawcharge}}/每次</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				res:[],
				array: [],
				index:0,
				addr:"",
				coinid:"",
				number:"",
				address:"",
				paypwd:"",
				openid:""
			};
		},
		onLoad:function(){
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.setAjax()
				},
				fail: () => {
					uni.navigateTo({
						url: '../../login/login'
					});
				}
			});
		},
		onNavigationBarButtonTap:function(e){
			uni.navigateTo({
				url: '../tbsqlist/tbsqlist'
			});
        },
		methods: {
			setAjax(){
				uni.request({
					url: this.$BASE_URL+'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=coin.tbsq&app=1&openid='+this.openid,
					success: res => {
						uni.hideLoading()
						console.log(res)
						this.res = res.data.coins
						var ary = ['请选择币种']
						for(var i in res.data.coins){
							ary.push(res.data.coins[i].coinname)
						}
						this.array = ary
					},
					fail: () => {},
					complete: () => {}
				});
			},
			bindPickerChange: function(e) {
				this.index = e.target.value
				this.coinid = this.res[e.target.value - 1].id
			},
			inputpaypwd(e){
				this.paypwd = e.detail.value
			},
			inputaddress(e){
				this.address = e.detail.value
			},
			inputnumber(e){
				this.number = e.detail.value
			},
			submit:function(e){
				if(this.address == ""){
					uni.showToast({
						title: '请输入钱包地址',
						icon:"none"
					});
				}else if(this.coinid == ""){
					uni.showToast({
						title: '请选择提现币种',
						icon:"none"
					});
				}else if(this.number == ""){
					uni.showToast({
						title: '请输入提现数量',
						icon:"none"
					});
				}else if(this.paypwd == ""){
					uni.showToast({
						title: '请输入支付密码',
						icon:"none"
					});
				}else{
					var data = {'coinid':this.coinid,'number': this.number,'address':this.address,'paypwd':this.paypwd}
					uni.request({
						url: this.$BASE_URL+'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=coin.tbsq&app=1&openid='+this.openid,
						method: 'POST',
						data: data,
						header:{'Content-Type':'application/x-www-form-urlencoded'},
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				}
			}
		}
	}
</script>

<style>.uni-list-cell-left{width:140upx;padding-right:0;}input{padding:14upx 24upx;}.uni-list:before{display:none;}</style>